<?php require_once('function/includes.php'); Session::start(); ?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Health Tracker</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Health Tracker">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <style>
      body {
        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
      }
    </style>
    <link href="css/bootstrap-responsive.css" rel="stylesheet">
	<link rel='stylesheet' type='text/css' href='css/datepicker.css' />
    <link rel="shortcut icon" href="ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="ico/apple-touch-icon-57-precomposed.png">
  </head>

  <body>

<?php include_once('nav.php'); ?>
    <div class="container">
    <div class="row">
		<div class="span5" style="background-color: #DCEAF4">
				<?php if (isset($_GET['role']) && ($_GET['role'] === 'patient' || $_GET['role'] === 'doctor')) { ?>
					<form action="function/signup_function.php" method="POST" class="form-horizontal">
                    <h1 style="padding-left:20px;">Register</h1>
					
					<!--Error-->
					<?php 
						if (isset($_SESSION['message'])) {
							foreach ($_SESSION['message'] as $message) {
								echo '<div class="alert alert-error"><button class="close" data-dismiss="alert" type="button">X</button>'.constant($message) . '</div>';
							}
							unset($_SESSION['message']);
						} 
						
						if (isset($_SESSION['saved'])) {
							$saved_form = $_SESSION['saved'];
							$username = $saved_form[0];
							$email = $saved_form[1];
							$firstname = $saved_form[2];
							$lastname = $saved_form[3];
							$gender = $saved_form[4];
							$address1 = $saved_form[5];
							$address2 = $saved_form[6];
							$city = $saved_form[7];
							$state = $saved_form[8];
							$country = $saved_form[9];
							$postal = $saved_form[10];
							$contact = $saved_form[11];
							unset($_SESSION['saved']);
						} else {
							$username = "";
							$email = "";
							$firstname = "";
							$lastname = "";
							$gender = "";
							$address1 = "";
							$address2 = "";
							$city = "";
							$state = "";
							$country = "";
							$postal = "";
							$contact = "";
						}
					?>
					<div class="control-group"><label class="control-label"  for="username">Username*:</label><div class="controls"> <input type="text" id="username" class="input-large" name="username" value="<?php echo $username ?>"/> </div></div>
					<div class="control-group"><label class="control-label"  for="password">Password*:</label><div class="controls"> <input type="password" class="input-large"  id="password1" name="password1"/> </div></div> 
					<div class="control-group"><label class="control-label"  for="password">Retype Password*:</label><div class="controls"> <input type="password" class="input-large"  id="password2" name="password2"/> </div></div> 
					<div class="control-group"><label class="control-label"  for="email">Email*:</label><div class="controls"> <input type="email" class="input-large"  id="email" name="email" value="<?php echo $email ?>"/> </div></div>
					<div class="control-group"><label class="control-label"  for="firstname">First name*:</label><div class="controls"> <input type="text" class="input-large"  id="firstname" name="firstname" value="<?php echo $firstname ?>"/>  </div></div>
					<div class="control-group"><label class="control-label"  for="lastname">Last name*:</label><div class="controls"> <input type="text" class="input-large"  id="lastname" name="lastname" value="<?php echo $lastname ?>"/> </div></div>
					<div class="control-group"><label class="control-label"  for="gender">Gender:</label><div class="controls">
					<select id="gender" name="gender">
						<option value="male">Male</option>
						<option value="female">Female</option>
					</select> </div></div>
				<div class="alert alert-success">
					<div class="control-group"><label class="control-label"  for="address">Address 1:</label><div class="controls"> <input type="text" class="input-large"  id="address1" name="address1" value="<?php echo $address1 ?>"/> </div></div>
					<div class="control-group"><label class="control-label"  for="address">Address 2:</label><div class="controls"> <input type="text" class="input-large"  id="address2" name="address2" value="<?php echo $address2 ?>"/> </div></div>
					<div class="control-group"><label class="control-label"  for="address">City:</label><div class="controls"> <input type="text" class="input-large"  id="city" name="city" value="<?php echo $city ?>"/> </div></div>
					<div class="control-group"><label class="control-label"  for="address">State:</label><div class="controls"> <input type="text" class="input-large"  id="state" name="state" value="<?php echo $state ?>"/> </div></div>
					<div class="control-group"><label class="control-label"  for="address">Country:</label><div class="controls"> <input type="text" class="input-large"  id="country" name="country" value="<?php echo $country ?>"/> </div></div>
					<div class="control-group"><label class="control-label"  for="address">Postal code:</label><div class="controls"> <input type="text" class="input-large"  id="postal" name="postal" value="<?php echo $postal ?>"/> </div></div>

				</div>
					<div class="control-group"><label class="control-label"  for="contact">Contact:</label><div class="controls"> <input type="text" class="input-large"  id="contact" name="contact" value="<?php echo $contact ?>"/> </div></div>
					
					<div class="control-group"><label class="control-label"  for="day">Day:</label><div class="controls">
                    <select id="day" name="day">
					<?php for ($i=1; $i<=31; $i++) {echo '<option value="'.$i.'">'.str_pad($i, 2, "0", STR_PAD_LEFT).'</option>';}?>
					</select></div></div>
					<div class="control-group"><label class="control-label"  for="month">Month:</label><div class="controls">
					<select id="month" name="month">
					<?php for ($i=1; $i<=12; $i++) {echo '<option value="'.$i.'">'.str_pad($i, 2, "0", STR_PAD_LEFT).'</option>';}?>
					</select></div></div>
					<div class="control-group"><label class="control-label"  for="year">Year:</label><div class="controls">
					<select id="year" name="year">
					<?php for ($i=2012; $i>=1900; $i--) {echo '<option value="'.$i.'">'.str_pad($i, 2, "0", STR_PAD_LEFT).'</option>';}?>
					</select> </div></div>

					<?php if ($_GET['role'] === 'patient') { ?>
						<input type="hidden" id="role" name="role" value="patient"/> 
						<div class="control-group"><label class="control-label"  for="bloodtype">Blood Type:</label><div class="controls"> <input type="text" class="input-large"  id="bloodtype" name="bloodtype" value="NA" /> </div></div>
						<div class="control-group"><label class="control-label"  for="allergy">Allergy:</label><div class="controls"> <input type="text" class="input-large"  id="allergy" name="allergy" /> </div></div>					
					<?php } else if ($_GET['role'] === 'doctor') { ?>
						<input type="hidden" id="role" name="role" value="doctor"/> 
						<div class="control-group"><label class="control-label" for="regno">Registration no*:</label> 
						<div class="controls"> <input type="text" id="regno" name="regno"/>  </div></div>
						
					<div class="alert alert-success" style="padding-left:25px">
						<div class="control-group"><label for="hospital" class="control-label">Hospital</label>
						<div class="controls">
						<?php 
						$hospital_list = Hospital::getHospitalList();
							if ($hospital_list !== null) {
						?>
						<select id="hospital" name="hospital" >
						<option value="0">Select hospital</option>
						<?php 

								foreach ($hospital_list as $hospital) {
									echo '<option value="' . $hospital['hospital_id'] . '">' . $hospital['hospital_name'] . '</option>';
								}
						?>
						<option value="0">Others</option>
						</select> </div></div>
						<?php } ?>
						<div class="control-group"><label for="hospitalName" class="control-label">Name:</label> 
						<div class="controls"><input type="text" id="hospitalName" name="hospitalName" /> </div></div>
						<div class="control-group"><label for="hospitalAddress" class="control-label">Address:</label> 
						<div class="controls"><input type="text" id="hospitalAddress" name="hospitalAddress" /> </div></div>
						<div class="control-group"><label for="hospitalContact" class="control-label">Contact:</label> 
						<div class="controls"><input type="text" id="hospitalContact" name="hospitalContact" /> </div></div>
					
						<div class="control-group"><label for="speciality" class="control-label">Speciality:</label> 
						<div class="controls"><input type="text" id="speciality" name="speciality"/>   </div></div>
                        </div>
					<?php } ?>
					<button type="submit" name="submit" class="btn btn-primary" style="margin:10px;">Register</button>
					<br />
					</form>
				<?php } else { ?>
					<a href="signup.php?role=patient">Create patient</a> |
					<a href="signup.php?role=doctor">Create doctor</a>
				<?php } ?>
			
    </div>
    </div> <!-- /container -->
	<script src='js/jquery-1.7.2.min.js'></script>
	<script src='js/jquery-ui-1.8.21.custom.min.js'></script>
	<script type="text/javascript" src="js/date.js"></script>
	<!--[if IE]><script type="text/javascript" src="js/jquery.bgiframe.js"></script><![endif]-->
	<script type="text/javascript" src="js/jquery.datePicker.js"></script>
	<script type='text/javascript'>
		$(document).ready(function() {
			$('.date-pick').datePicker(
			{
				startDate: '01/01/1970',
				endDate: (new Date()).asString()
			}
			).val(new Date().asString()).trigger('change');
		});
	</script>
  </body>
</html>